using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OF.DB.DataAccess;
using OF.DB.Test.Entity;

namespace OF.DB.Test.DataAccess
{    
    public static partial class UserDao
    {
        private const string AddSql = @"INSERT INTO dbo.[User](name, jointime, account, pwd) VALUES(@name, @jointime, @account, @pwd);
                SELECT id = SCOPE_IDENTITY();";
        private const string UpdateSql = @"UPDATE dbo.[User] SET name = @name, account = @account, pwd = @pwd WHERE id = @id;";
        private const string GetByIdSql = @"SELECT * FROM dbo.[User] WITH(NOLOCK) WHERE id = @id";
        private const string DeleteByIdSql = @"DELETE FROM dbo.[User] WHERE id = @id;";
        private const string GetALLListSql = @"SELECT * FROM dbo.[User] WITH(NOLOCK)";
		
        private static SqlParameter[] GetAddSqlParams(User entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@name", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.name) },
               new SqlParameter("@jointime", SqlDbType.DateTime) { Value = DBHelper.GetParamValue(entity.jointime) },
               new SqlParameter("@account", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.account) },
               new SqlParameter("@pwd", SqlDbType.VarBinary) { Value = DBHelper.GetParamValue(entity.pwd) }
            };
        }

        private static SqlParameter[] GetUpdateSqlParams(User entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@id", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.id) },
               new SqlParameter("@name", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.name) },
               new SqlParameter("@account", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.account) },
               new SqlParameter("@pwd", SqlDbType.VarBinary) { Value = DBHelper.GetParamValue(entity.pwd) }
            };
        }

        private static SqlParameter[] GetGetByIdSqlParams(User entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@id", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.id) }
            };
        }

        private static SqlParameter[] GetDeleteByIdSqlParams(User entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@id", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.id) }
            };
        }
    }
}